import React, { Component } from 'react'
import axios from 'axios';

export default class Search extends Component {
  search=()=>{
    const {keyWordElement:{value:keyWord}}=this
    this.props.updateState({isFirst:false,isLoading:true})
    axios.get(`http://localhost:3000/api1/search/users?q=${keyWord}`).then(
      (response)=>{
        this.props.updateState({users:response.data.items,isLoading:false})
      },
      (error)=>{
        this.props.updateState({err:error.message,isLoading:false})
      })
  }
  render() {
    return (
        <section className="jumbotron">
            <h3 className="jumbotron-heading">搜索Github用户</h3>
            <div>
            <input ref={c=>this.keyWordElement=c} type="text" placeholder="输入名字进行搜索"/>&nbsp;
            <button onClick={this.search}>搜索</button>
            </div>
        </section>
    )
  }
}
